package com.katze.ssh.sftp;

import org.apache.sshd.sftp.client.SftpClient;

import java.util.zip.ZipEntry;

public class ZipEntity extends ZipEntry {

    private int offset;
    private final String filePath;

    public ZipEntity(String path, String name, SftpClient.Attributes attributes) {
        super(attributes.isDirectory()? name + "/":name);
        setSize(attributes.getSize());
        if (attributes.getCreateTime() != null) setCreationTime(attributes.getCreateTime());
        if (attributes.getAccessTime() != null) setLastAccessTime(attributes.getAccessTime());
        if (attributes.getModifyTime() != null) setLastModifiedTime(attributes.getModifyTime());
        this.filePath = path + "/" + name;
    }

    public void setOffset(int length) {
        this.offset += length;
    }

    public int getOffset() {
        return offset;
    }

    public String getProgress() {
        if (getOffset() != getSize()) {
            return String.format("%.2f", offset * 100.0 / getSize());
        } else {
            return "100";
        }
    }

    public String getFilePath() {
        return filePath;
    }
}
